package enterprises

import grails.test.*

class ConsumerTests extends GrailsUnitTestCase {
	Consumer consumer
	TypeConsumer typeConsumer = new TypeConsumer()

	protected void setUp() {
		super.setUp()
		consumer = new Consumer(name:"", typeConsumer:typeConsumer)
		mockForConstraintsTests(Consumer, [consumer])
	}

	protected void tearDown() {
		super.tearDown()
	}
	
	void testToString() {
		assertEquals "asd", new Consumer(name:"asd").toString()
	}

	void testEmptyName() {
		consumer.validate()
		assertFalse consumer.validate()
		assertEquals "blank", consumer.errors.name
	}

	void testMinSize() {
		consumer.name = "as"
		assertFalse consumer.validate()
		assertEquals "minSize", consumer.errors.name
	}

	void testUniqueName() {
		mockDomain(Consumer, [
			new Consumer(name:"asd", typeConsumer:typeConsumer)
		])
		consumer.name = "asd"
		assertFalse consumer.validate()
		assertEquals "unique", consumer.errors.name
	}
}
